package edu.rutgers.moko.data;

import java.io.Serializable;
import java.util.Date;

/**
 * 
 * @author Darja Krushevskaja
 *
 */

public class FeedData implements Serializable {

	private static final long serialVersionUID = 1;

	private Date date;

	private String batteryStatus;

	private String batteryCapacity;

	private String timeToEmpty;

	private String currentBrightness;

	private String timezone;

	private String bluetooth;

	public String getBatteryCapacity() {
		return batteryCapacity;
	}

	public void setBatteryCapacity(String batteryCapacity) {
		this.batteryCapacity = batteryCapacity;
	}

	public String getBatteryStatus() {
		return batteryStatus;
	}

	public void setBatteryStatus(String batteryStatus) {
		this.batteryStatus = batteryStatus;
	}

	public String getBluetooth() {
		return bluetooth;
	}

	public void setBluetooth(String bluetooth) {

		if (bluetooth.equals("0")) {
			this.bluetooth = "off";
		} else {
			this.bluetooth = "on";
		}

	}

	public String getCurrentBrightness() {
		return currentBrightness;
	}

	public void setCurrentBrightness(String currentBrightness) {
		this.currentBrightness = currentBrightness;
	}

	public String getTimezone() {
		return timezone;
	}

	public void setTimezone(String timezone) {
		this.timezone = timezone;
	}
	
	
	public Boolean batteryStatusChanged(FeedData f){
		if (f.getBatteryStatus() == null) {
			if (batteryStatus != null)
				return true;
		} else if (!batteryStatus.equals(f.getBatteryStatus()))
			return true;
		return false;
	}
	
	public Boolean batteryCapacityChanged(FeedData f){
		if (f.getBatteryCapacity() == null) {
			if (batteryCapacity != null)
				return true;
		} else if (!batteryCapacity.equals(f.getBatteryCapacity()))
			return true;
		return false;
	}
	
	public Boolean timeToEmptyChanged(FeedData f){
		if (f.getTimeToEmpty() == null) {
			if (timeToEmpty != null)
				return true;
		} else if (!timeToEmpty.equals(f.getTimeToEmpty()))
			return true;
		return false;
	}

	public Boolean currentBrightnessChanged(FeedData f){
		if (f.getCurrentBrightness() == null) {
			if (currentBrightness != null)
				return true;
		} else if (!currentBrightness.equals(f.getCurrentBrightness()))
			return true;
		return false;
	}
	
	public Boolean timezoneChanged(FeedData f){
		if ( f.getTimezone() == null) {
			if (timezone != null)
				return true;
		} else if (!timezone.equals(f.getTimezone()))
			return true;
		return false;
	}
	
	public Boolean bluetoothChanged(FeedData f){
		if (f.getBluetooth() == null) {
			if (bluetooth != null)
				return true;
		} else if (!bluetooth.equals(f.getBluetooth()))
			return true;
		return false;
	}


	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result
				+ ((batteryCapacity == null) ? 0 : batteryCapacity.hashCode());
		result = PRIME * result
				+ ((batteryStatus == null) ? 0 : batteryStatus.hashCode());
		result = PRIME * result
				+ ((bluetooth == null) ? 0 : bluetooth.hashCode());
		result = PRIME
				* result
				+ ((currentBrightness == null) ? 0 : currentBrightness
						.hashCode());
		result = PRIME * result
				+ ((timezone == null) ? 0 : timezone.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final FeedData other = (FeedData) obj;
		if (batteryCapacity == null) {
			if (other.batteryCapacity != null)
				return false;
		} else if (!batteryCapacity.equals(other.batteryCapacity))
			return false;
		if (batteryStatus == null) {
			if (other.batteryStatus != null)
				return false;
		} else if (!batteryStatus.equals(other.batteryStatus))
			return false;
		if (bluetooth == null) {
			if (other.bluetooth != null)
				return false;
		} else if (!bluetooth.equals(other.bluetooth))
			return false;
		if (currentBrightness == null) {
			if (other.currentBrightness != null)
				return false;
		} else if (!currentBrightness.equals(other.currentBrightness))
			return false;
		if (timezone == null) {
			if (other.timezone != null)
				return false;
		} else if (!timezone.equals(other.timezone))
			return false;
		return true;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getTimeToEmpty() {
		return timeToEmpty;
	}

	public void setTimeToEmpty(String timeToEmpty) {
		this.timeToEmpty = secondsToString(Long.valueOf(timeToEmpty));
	}
	private String secondsToString(long time){
	    int seconds = (int)(time % 60);
	    int minutes = (int)((time/60) % 60);
	    int hours = (int)((time/3600) % 24);
	    String secondsStr = (seconds<10 ? "0" : "")+ seconds;
	    String minutesStr = (minutes<10 ? "0" : "")+ minutes;
	    String hoursStr = (hours<10 ? "0" : "")+ hours;
	    return new String(hoursStr + ":" + minutesStr + ":" + secondsStr);
	  }
}
